//
//  MQVideoEnterViewCell.m
//  MQ
//
//  Created by lanou on 15/10/26.
//  Copyright © 2015年 徐永祥. All rights reserved.
//

#import "MQVideoEnterViewCell.h"
#import <UIImageView+WebCache.h>
@implementation MQVideoEnterViewCell





-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle =UITableViewCellSeparatorStyleNone;
        
        
        _backGroundView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 0, screen_width-20, 100)];
//        _backGroundView.image = [UIImage imageNamed:@"bg_share_large"];
        [self.contentView addSubview:_backGroundView];
        
        
        _pictureView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 30, 30)];
        _pictureView.layer.cornerRadius = 15;
        _pictureView.layer.masksToBounds = YES;
        [self.backGroundView addSubview:_pictureView];
        
    
        _nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 5, 100, 10)];
        _nameLabel.font =[UIFont fontWithName:@"Helvetica-Bold" size:13];
        _nameLabel.alpha = 0.5;
        
        [self.backGroundView addSubview:_nameLabel];
        
        _timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 25, 130, 10)];
        _timeLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:13];
        _timeLabel.alpha = 0.5;
        
        [self.backGroundView addSubview:_timeLabel];
        
        
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 45, screen_width-30, 20)];
        _titleLabel.alpha = 0.8;
        [self.backGroundView addSubview:_titleLabel];
        
        _gifView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 70, screen_width-20, 120)];
        [self.backGroundView addSubview:_gifView];
        
        
        _tagButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _tagButton.frame = CGRectMake(5, 190, 20, 20);
        [_tagButton setBackgroundImage:[UIImage imageNamed:@"biaoqian"] forState:(UIControlStateNormal)];
        [self.backGroundView addSubview:_tagButton];
        
        _tagLabel = [[UILabel alloc]initWithFrame:CGRectMake(25, 190, screen_width-35, 20)];
        _tagLabel.alpha = 0.5;
        _tagLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:13];
        
        [self.backGroundView addSubview:_tagLabel];
        
        _upButton =[UIButton buttonWithType:(UIButtonTypeCustom)];
        _upButton.frame = CGRectMake(20, 220, 20, 20);
        [_upButton setBackgroundImage:[UIImage imageNamed:@"unzan"] forState:(UIControlStateNormal)];
        [self.backGroundView addSubview:_upButton];
        
        _upCountLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 220, 80, 20)];
        _upCountLabel.alpha = 0.5;
        _upCountLabel.font = [UIFont systemFontOfSize:13];
        [self.backGroundView addSubview:_upCountLabel];
        
        _downButton=[UIButton buttonWithType:(UIButtonTypeCustom)];
        _downButton.frame = CGRectMake((screen_width-20)/2, 225, 20, 20);
        [_downButton setBackgroundImage:[UIImage imageNamed:@"uncai"] forState:(UIControlStateNormal)];
        [self.backGroundView addSubview:_downButton];
        
        _shareButton =[UIButton buttonWithType:(UIButtonTypeCustom)];
        _shareButton.frame = CGRectMake(220, 220, 20, 20);
        [_shareButton setBackgroundImage:[UIImage imageNamed:@"fenxiang"] forState:(UIControlStateNormal)];
        [self.backGroundView addSubview:_shareButton];
        
        
        _shareLabel = [[UILabel alloc]initWithFrame:CGRectMake(250, 220, 80, 20)];
        _shareLabel.alpha = 0.5;
        _shareLabel.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:_shareLabel];
        
        _lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 215, screen_width-40, 1)];
        _lineLabel.backgroundColor = [UIColor grayColor];
        _lineLabel.alpha = 0.5;
        [self.backGroundView addSubview:_lineLabel];
        
        _downCountLabel = [[UILabel alloc]initWithFrame:CGRectMake((screen_width-20)/2+20, 225, 80, 20)];
        _downCountLabel.font =[UIFont systemFontOfSize:13];
        _downCountLabel.alpha = 0.5;
        [self.contentView addSubview:_downCountLabel];
        
        
        _playCountLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.gifView.bounds.size.height-20, 100, 20)];
        _playCountLabel.textColor = [UIColor whiteColor];
        _playCountLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
        
        [self.gifView addSubview:_playCountLabel];
        
        _playTimeLabel = [[UILabel alloc]initWithFrame:CGRectMake(screen_width-60, self.gifView.bounds.size.height-20, 80, 20)];
        _playTimeLabel.font =[UIFont fontWithName:@"Helvetica-Bold" size:14];
        
        _playTimeLabel.textColor = [UIColor whiteColor];
        [self.gifView addSubview:_playTimeLabel];
        
        UIButton * playButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        playButton.frame = CGRectMake((screen_width-40)/2-10,self.gifView.bounds.size.height/2-10, 40, 40);
        playButton.layer.cornerRadius = 20;
        playButton.layer.masksToBounds = YES;
        [playButton setBackgroundImage:[UIImage imageNamed:@"bofan"] forState:(UIControlStateNormal)];
        playButton.backgroundColor = [UIColor whiteColor];
        [self.gifView addSubview:playButton];
        
        
    }
    
    return self;
}


-(void)configCellWithModel:(MQVideoEnterModel *)model
{
    
    
    
    [self.pictureView sd_setImageWithURL:[NSURL URLWithString:model.list.uModel.header[0]]];
    [self.gifView sd_setImageWithURL:[NSURL URLWithString:model.list.video.thumbnail[0]]];
    self.gifView.frame = CGRectMake(10, 70, screen_width-40,model.list.video.height*(screen_width-40)/model.list.video.width);
    
    ((UIButton *)self.gifView.subviews[2]).frame =CGRectMake((screen_width-40)/2-10,self.gifView.bounds.size.height/2-10, 40, 40);
    _tagButton.frame = CGRectMake(10, model.list.video.height*(screen_width-40)/model.list.video.width+70+10, 20, 20);
    self.tagLabel.frame =CGRectMake(35, model.list.video.height*(screen_width-40)/model.list.video.width+70+10, screen_width-35, 20);
    self.upButton.frame =CGRectMake(30, model.list.video.height*(screen_width-40)/model.list.video.width+70+30+15, 20, 20);
    self.upCountLabel.frame =CGRectMake(55, model.list.video.height*(screen_width-40)/model.list.video.width+70+30+2.5+15, 80, 20);
    self.shareButton.frame =CGRectMake((screen_width-20)-70,model.list.video.height*(screen_width-40)/model.list.video.width+70+30+15 , 20, 20);
    self.shareLabel.frame =CGRectMake(screen_width-20-35,model.list.video.height*(screen_width-40)/model.list.video.width+70+30+2.5 +15, 80, 20);
       
     _downButton.frame = CGRectMake((screen_width-20)/2-20,model.list.video.height*(screen_width-40)/model.list.video.width+70+30+2.5+15 , 20, 20);
    self.downCountLabel.frame =CGRectMake((screen_width-20)/2+15,model.list.video.height*(screen_width-40)/model.list.video.width+70+30+2.5+15 , 80, 20);
       _playCountLabel.frame = CGRectMake(0, self.gifView.bounds.size.height-20, 100, 20);
    _playCountLabel.text =[NSString stringWithFormat:@"%ld次播放",(long)model.list.video.playcount];
    _playTimeLabel.frame = CGRectMake(screen_width-80, self.gifView.bounds.size.height-20, 80, 20);
    _playTimeLabel.text = [NSString stringWithFormat:@"%02ld:%02ld",model.list.video.duration/60,model.list.video.duration%60 ];
    self.downCountLabel.text = [NSString stringWithFormat:@"%ld",(long)model.list.down];
    self.nameLabel.text = model.list.uModel.name;
    self.timeLabel.text = model.list.passtime;
    self.titleLabel.text = model.list.text;
    [self.gifView sd_setImageWithURL:[NSURL URLWithString:model.list.video.thumbnail[0] ]];
    self.upCountLabel.text = [NSString stringWithFormat:@"%ld",(long)model.list.up];
   
    self.shareLabel.text = [NSString stringWithFormat:@"%ld",(long)model.list.bookmark];
    self.commentLabel.text = [NSString stringWithFormat:@"%ld",(long)model.list.comment];
    NSMutableArray * arr = [NSMutableArray array];
    for (NSDictionary * dic in model.list.tags) {
        [arr addObject:[dic objectForKey:@"name"]];
    }
    
    self.tagLabel.text = [arr componentsJoinedByString:@" "];
    _lineLabel.frame =  CGRectMake(0, model.list.video.height*(screen_width-40)/model.list.video.width+70+30+50, screen_width, 2);
    self.backGroundView.frame = CGRectMake(10, 0, screen_width-20, model.list.video.height*(screen_width-40)/model.list.video.width+70+30+50);
    
}
+(CGFloat)heightForRowWithmodel:(MQVideoEnterModel *)model
{
    return model.list.video.height*(screen_width-40)/model.list.video.width+70+30 +65;
    
}





- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
